import userApi from "@/axios/userApi"
import status from "@/commons/statusCode"
export default {
    namespaced: true,
    state: () => ({
        info: {
            id: '',
            username: '',
            nickname: '',
            avatar: '',
            bgImg: '',
            intro: ''
        },
        isLogin: false,
    }),
    mutations: {
        login(state, payload) {
            state.info = payload
            state.isLogin = true
            window.localStorage.setItem('userInfo',JSON.stringify(state.info))
        },
        logout(state, payload) {
            state.isLogin = false
            state.info = {}
            window.localStorage.removeItem('userInfo')
        }
    },
    actions: {
        updateUser({commit},{_this}){
            userApi.getUserInfo()
            .then(({data})=>{
                    commit('login', data.data)
                    _this.$message.success("保存成功")
                
            })
         
        }
    }
}